package cn.niit.pm.service.impl;

import cn.niit.pm.dao.DeclareMapper;
import cn.niit.pm.entity.Attendance;
import cn.niit.pm.entity.Declare;
import cn.niit.pm.service.DeclareService;
import cn.niit.pm.service.ServiceInterface;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


@Service
public class DeclareServiceImpl implements ServiceInterface<Declare> {
    @Resource
    private DeclareMapper mapper;

    @Override
    public PageInfo select(Declare declare, int pageSize, int pageNumber) {
        //使用PageHelper设置分页，为了安全分页，后边最好紧跟mybatis mapper方法
        //注意这里看起来似乎是属于内存分页，但其实PageHelper插件对mybatis执行流程进行了增强，属于物理分页
        PageHelper.startPage(pageSize, pageNumber);
        List<Declare> page = mapper.findByPage(declare);
        PageInfo<Declare> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @Override
    public void insert(Declare declare) {
        declare.setDelFlag(0);
        declare.setCreateUserId(1L);
        declare.setCreateUserName("Test");
        declare.setGmtCreate(new Date());
        mapper.insert(declare);
    }

    @Override
    public void update(Declare declare) {
        declare.setDelFlag(0);
        declare.setCreateUserId(1L);
        declare.setCreateUserName("Test");
        declare.setGmtCreate(new Date());
        mapper.update(declare);
    }

    @Override
    public void delete(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public Declare selectById(Long id) {
        return mapper.selectById(id);
    }
    /*

    */
/**
     * 根据查询条件（已封装为recruit对象），查询符合所有条件的公告信息
     * @param declare
     * @return
     *//*

    @Lazy
    @Override
    public List<Declare> selectListByDeclare(Declare declare) {
        return declareMapper.selectListByDeclare(declare);
    }

    */
/**
     * 添加公告信息
     * @param declare
     * @return
     *//*

    @Override
    public int insertDeclare(Declare declare) {
        return declareMapper.insertDeclare(declare);
    }

    */
/**
     * 查询公告信息
     * @param title
     * @return
     *//*

    @Override
    public Declare selectByTitle(String title) {
        return declareMapper.selectByTitle(title);
    }

    */
/**
     * 更新公告信息
     * @param declare
     * @return
     *//*

    @Override
    public int updateDeclare(Declare declare) {
        return declareMapper.updateDeclare(declare);
    }

    */
/**
     * 删除公告信息
     * @param title
     * @return
     *//*

    @Override
    public int deleteByDeclare(String title) {
        return 0;
    }

    */
/**
     * 添加公告信息
     * @param declare
     * @return
     *//*

    @Override
    public int add(Declare declare) {
        return declareMapper.insertDeclare(declare);
    }
*/


}
